package com.app.view.component.resource 
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.utils.Dictionary;
	
	public class Resourecs extends EventDispatcher 
	{
		
		private var _count:int = 0;
		private var _index:int = 0;
		
		private var _loaders:Array = null;
		
		private var _connect:Dictionary = null;
		public function Resourecs(count:int = 0) 
		{
			_count = count;
			_loaders = [];	
		}

		public function addResourec(obj:Object = null):ResourceData
		{
			var data:ResourceData = new ResourceData();
			data.addEventListener(Event.COMPLETE, onComplete);
			data.uid = obj.uid;
			data.type = obj.type;
			data.url = obj.url;
			data.dir = obj.dir;
			data.scale = obj.scale;
			_loaders[_loaders.length] = data;
			return data;
		}
		
		public function start():void
		{
			for each(var data:ResourceData in _loaders)
			{
				data.start();
			}
		}
		
		private function onComplete(event:Event):void
		{
			_index++;
			
			if (_count <= _index)
			{
				dispatchEvent(event);
			}
		}
	}
}